<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="../../css/base.css">
    <link rel="stylesheet" href="../../css/detail/login.css">
    <link rel="stylesheet" href="../../css/detail/register.css">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <div class="gold-login">
            <!-- <div class="head">
                        <div class="h-left">×</div>
                        <div class="h-middle"></div>
                        <div class="h-right"></div>
                    </div> -->
            <div class="fold-register-content">
                <p class="fold-register-title">修改密码</p>
            </div>
            <div class="fold-login-form">
                <form action="">
                    <div class="fold-form-con">
                        <input type="text" class="gold-password" name="phone" placeholder="请输入手机号码" onkeyup="this.value=this.value.replace(/\s+/g,'')">
                    </div>
                    <div class="fold-form-con" style="position:relative;">
                        <input type="text" class="gold-password" name="verify" placeholder="请输入短信验证码">
                        <span class="fold-verify" @click="Onsubmit">发送验证码</span>
                        <span class="fold-ver">60</span>
                    </div>
                    <div class="fold-form-con">
                        <input type="password" class="gold-password" name="password" type="password" placeholder="请输入密码，8-20位数字或字母密码" onkeyup="this.value=this.value.replace(/\s+/g,'')">
                    </div>
                    <div class="fold-form-con">
                        <input type="password" class="gold-password" name="agin-password" type="password" placeholder="请再次输入密码" onkeyup="this.value=this.value.replace(/\s+/g,'')">
                    </div>
                    <!--<div class="fold-form-con">-->
                        <!--<a class="register-fen" href="javascript:0;">点击核对分享人信息</a>-->
                    <!--</div>-->
                    <div class="login-con">
                        <a class="gold-login-a" href="javascript:0;" @click="submit">确认</a>
                    </div>
                </form>
            </div>
            <!-- <div class="gold-farget">
                <a href="">忘记密码？</a>
            </div> -->
        </div>
    </div>
    <script src="../../js/common.js"></script>
    <script src="../../js/jquery-2.2.3.min.js"></script>
    <script src="../../js/rem.js"></script>
    <script src="../../js/common.js"></script>

    <script src="js/cc.js"></script>
    <script src="js/vue.min.js"></script>
    <script src="js/vue-resource.min.js"></script>
    <script src="layer-v3.1.1/layer/layer.js"></script>
    <script>
    	$(function(){
    		var url = location.search;
	        var theRequest = new Object();
	        if (url.indexOf("?") != -1) {
	            var str = url.substr(1);
	            strs = str.split("&");
	            for (var i = 0; i < strs.length; i++) {
	                theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
	            }
	        }
	        if(theRequest.hasOwnProperty("userPhone")){
	            $('.gold-password-fen').val(theRequest.userPhone);
	            $('.gold-password-fen').attr('disabled','disabled');
	        }
    	})
        var goodsId=decodeURIComponent(getQueryString("id"));

        var app = new Vue({
            el:'#app',
            methods:{
                Onsubmit:function(){
                    let  userPhone= $('input[name="phone"]').val()
                 
                    console.log(222)
                    this.$http.post(SURL + '/jfd/users/getCode',{userPhone:userPhone,type:2},{emulateJSON : true}).then(function (res) {
                        if(res.body.code == 500){
                            layer.msg(res.body.msg);
                           
                            }else {
                                layer.msg(res.body.msg);
                                $('.fold-verify').css("display","none")
                               $('.fold-ver').css("display","block")
                                var time=parseInt($(".fold-ver").text());
                                setTime=setInterval(function(){
                                    if(time<=0){
                                        clearInterval(setTime);
                                        $('.fold-verify').css("display","block")
                                        $('.fold-ver').css("display","none")
                                        return;

                                    }
                                    time--;
                                    $(".fold-ver").text(time);
                                },1000);
                            }
                            
                        })
                },
                submit:function () {
                    let userName = $('.gold-username').val(),
                        userPhone= $('input[name="phone"]').val(),
                        code = $('input[name="verify"]').val(),
                        password= $('input[name="password"]').val(),
                        invitePhone= $('input[name="fen-phone"]').val(),
                        passwordT= $('input[name="agin-password"]').val();
                    // console.log(userName)
                    // console.log(password)
                    // console.log(userPhone)
                    // console.log(invitePhone)
                    console.log(passwordT)
                    if(!(/^1\d{10}$/.test(userPhone))){
                        alert("手机号码有误，请重填");
                        return false;
                    }else if( password.length < 8){
                        layer.msg('密码不能小于8位');
                    }else if(password.length > 20){
                        layer.msg('密码不能大于20位');
                    }else if(passwordT != password){
                        layer.msg('二次输入密码不正确');
                    }else {
                        this.$http.post(SURL + '/jfd/users/checkCode',{userPhone:userPhone,code:code,type:2},{emulateJSON : true}).then(function (res) {
                        if(res.body.code == 500){
                                layer.msg(res.body.msg);
                            }else {
                                this.$http.post(SURL +  '/jfd/users/forgetPassword',{newPassword:password,userPhone:userPhone,type:2,typeFlag:1},{emulateJSON : true}).then(function (res) {
                                    console.log(res.body.code);
                                    if(res.body.code == 500){
                                        layer.msg(res.body.msg);
                                    }else {
                                        layer.msg(res.body.msg);
                                        setTimeout(function () {
                                            location.href = 'login.html'
                                        },500)
                                    }
                                })
                            }
                            
                        })
                       
                    }

                }
            }
        })
    </script>
</body>

</html>
